﻿package tests;
import flash.display.Shape;
import flash.geom.Rectangle;
import fpc.containers.ScrollBox;
import fpc.controls.buttons.Button;
import fpc.controls.mutators.ScrollBar;
import fpc.layouts.ILayout;
import fpc.layouts.VLayout;
import fpc.styles.Style;
import glam.skins.GlamScrollBar;

class ScrollBarTest extends GenericTest
{
	public function new() 
	{
		super();
	}
	
	override function init()
	{
		var style = new Style()
			.setSkin(ScrollBar.SKIN_TYPE_SCROLL_BAR, new GlamScrollBar());
		
		var offset = 0.;
			
		var scrollBar = new ScrollBar(true);
		scrollBar.y = offset;
		scrollBar.style = style;
		scrollBar.fullScrollSize = 200;
		scrollBar.pageScrollSize = 300;
		scrollBar.addTo(this);
		offset += scrollBar.height;
		
		var scrollBar = new ScrollBar(true);
		scrollBar.y = offset;
		scrollBar.style = style;
		scrollBar.width = 100;
		scrollBar.fullScrollSize = 200;
		scrollBar.pageScrollSize = 150;
		scrollBar.enabled = false;
		scrollBar.addTo(this);
		offset += scrollBar.height;
		
		var scrollBar = new ScrollBar(true);
		scrollBar.y = offset;
		scrollBar.style = style;
		scrollBar.width = 100;
		scrollBar.fullScrollSize = 200;
		scrollBar.pageScrollSize = 1;
		scrollBar.addTo(this);
		offset += scrollBar.height;
		
		var scrollBar = new ScrollBar(false);
		scrollBar.style = style;
		scrollBar.x = 200;
		scrollBar.fullScrollSize = 200;
		scrollBar.pageScrollSize = 20;
		scrollBar.addTo(this);
		
		var scrollBar = new ScrollBar(false);
		scrollBar.style = style;
		scrollBar.x = 100;
		scrollBar.y = 200;
		scrollBar.height = 100;
		scrollBar.fullScrollSize = 200;
		scrollBar.pageScrollSize = 100;
		scrollBar.addTo(this);
		
		var shape = new Shape();
		shape.y = 200;
		addChild(shape);
		var g = shape.graphics;
		g.lineStyle(0, 0x000000);
		g.moveTo(0, 0);
		g.lineTo(100, 200);
		g.moveTo(0, 0);
		g.lineTo(50, 200);
		g.moveTo(0, 0);
		g.lineTo(100, 0);
		g.moveTo(0, 50);
		g.lineTo(100, 100);
		g.moveTo(0, 199);
		g.lineTo(100, 199);
		shape.scrollRect = new Rectangle(0, 0, 100, 100);
		scrollBar.heraldChange.add(function(scrollBar) {
			shape.scrollRect = new Rectangle(0, scrollBar.value, 100, 100);
		});
		
		scrollBar.value = 50;
		
		var button = new Button('Button 0');
		button.addTo(this);
		button.y = offset;
		offset += button.height;
		
		var button = new Button('Button 1');
		button.addTo(this);
		button.y = offset;
		button.enabled = false;
		offset += button.height;
		
		_scrollBox = new ScrollBox<ILayout>();
		_scrollBox.style = style;
		_scrollBox.x = 300;
		_scrollBox.y = 200;
		_scrollBox.addTo(this);
		
		var layout = new VLayout();
		layout.autoSize = false;
		_scrollBox.layout = layout;
		
		for (i in 0 ... 11)
		{
			var button = new Button('Button ' + i);
			button.percentsWidth = 100;
			layout.add(button);
		}
		var button = new Button('Unscaled Button');
		button.width = 170;
		layout.add(button);
	}
	
	var _scrollBox:ScrollBox<ILayout>;
	
	override function resize(width:Float, height:Float)
	{
		_scrollBox.width = width - _scrollBox.x;
		_scrollBox.height = height - _scrollBox.y;
	}
}